<script lang="ts" setup>
import { ref } from 'vue'
import { useI18n } from '@/hooks/web/useI18n'
import { useMessage } from '@/hooks/web/useMessage'

import { BasicModal, useModalInner } from '@/components/Modal'
import { getOrder } from '@/api/vr/order'
import {detailSchema} from './order.data'
import { Description, useDescription } from '@/components/Description'

defineOptions({ name: 'BpmFormModal' })

const emit = defineEmits(['success', 'register'])
const { t } = useI18n()
const { createMessage } = useMessage()
 
const datas = ref()

const [registerDesc] = useDescription({
  schema: detailSchema,
  data: datas,
})

const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
  setModalProps({ confirmLoading: false })
  const res = await getOrder(data.record.id)
  datas.value = res
  // formConfig.value.option = res.conf
})

async function handleSubmit() {
  try {
    closeModal()
    emit('success')
    createMessage.success(t('common.saveSuccessText'))
  }
  finally {
    setModalProps({ confirmLoading: false })
  }
}
</script>

<template>
  <BasicModal v-bind="$attrs" title="查看订单详情" @register="registerModal" @ok="handleSubmit">
    <Description :column="2" @register="registerDesc" />
  </BasicModal>
</template>
